/*helper class*/
function Callback(param, func) {
	this.data = param;
	this.cb = func;
}

$N.util = $N.util || {};

$N.util = (function ($N) {
	function ajaxPost(postURL, para, cb) {
		var url = postURL;
		console.log("ajaxPost : " + postURL + para.jsonstring);
		$.post(url, para, cb);
	}

	function _getUserName() {
		return localStorage.getItem("XPP_USERNAME");
	}
    
	Date.prototype.format = function (format) {
		var date = {
			"M+" : this.getMonth() + 1,
			"d+" : this.getDate(),
			"h+" : this.getHours(),
			"m+" : this.getMinutes(),
			"s+" : this.getSeconds(),
			"q+" : Math.floor((this.getMonth() + 3) / 3),
			"S+" : this.getMilliseconds()
		};
		if (/(y+)/i.test(format)) {
			format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
		}
		for (var k in date) {
			if (new RegExp("(" + k + ")").test(format)) {
				format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
			}
		}
		return format;
	};

	var healthDataTypeEnum = [{
			unit : "千米",
			type : "跑步",
			value : "101"
		}, {
			unit : '分钟',
			type : '跑步',
			value : "102"
		}, {
			unit : '大卡',
			type : '饮食',
			value : "103"
		}, {
			unit : '根',
			type : '抽烟',
			value : "104"
		}, {
			unit : '瓶',
			type : '喝酒',
			value : "105"
		}, {
			unit : '个',
			type : '仰卧起坐',
			value : "106"
		}, {
			unit : '个',
			type : '引体向上',
			value : "107"
		}, {
			unit : '个',
			type : '俯卧撑',
			value : "108"
		}, {
			unit : '厘米',
			type : '身高',
			value : "201"
		}, {
			unit : '千克',
			type : '体重',
			value : "202"
		}, {
			unit : '毫克',
			type : '餐后血糖',
			value : "301"
		}, {
			unit : '毫克',
			type : '餐前血糖',
			value : "302"
		}, {
			unit : '毫米汞柱',
			type : '血压高压',
			value : "303"
		}, {
			unit : '毫米汞柱',
			type : '血压低压',
			value : "304"
		}, {
			unit : '毫克',
			type : '血氧',
			value : "305"
		}, {
			unit : '次',
			type : '心率',
			value : "401"
		}, {
			unit : '度',
			type : '体温',
			value : "402"
		}, {
			unit : '厘米',
			type : '腰围',
			value : "403"
		}, {
			unit : '厘米',
			type : '胸围',
			value : "404"
		}
	];

	var personProfileUploadURL = "http://localhost/cakephp/mobileUsersAdapter/uploadpersonprofile";
	var personProfileDownloadURL = "http://localhost/cakephp/mobileUsersAdapter/downloadpersonprofile";
	var serviceUrl = "http://localhost/cakephp/mobileUsersAdapter/";
	var detachManagedPersonsURL = "http://localhost/cakephp/mobileUsersAdapter/detachManagedPersons";
    var homePageMode = 0;
	function getPersonProfileUploadURL() {
		return personProfileUploadURL;
	}

	function getPersonProfileDownloadURL() {
		return personProfileDownloadURL;
	}

	function getServiceURL() {
		return serviceURL;
	}

	function getDetachManagedPersonsURL() {
		return detachManagedPersonsURL;
	}
	
	function showDialog(dlgTitle, dlgBody, doneCb, cancelCb) {

		var popupOpt = {
			title : dlgTitle,
			message : dlgBody,
			cancelText : "取消",
			cancelCallback : cancelCb,
			doneText : "确定",
			doneCallback : doneCb,
			cancelOnly : false,
		};
		$.ui.popup(popupOpt);
	}
	function setHomePageMode(mode) {
	    homePageMode = mode;
	}
	
	function getHomePageMode() {
	    return homePageMode;
	}
	
	return {
		ajaxPost    :     ajaxPost,
		getUserName :     _getUserName,
		healthDataTypeEnum : healthDataTypeEnum,
		getPersonProfileDownloadURL : getPersonProfileDownloadURL,
		getPersonProfileUploadURL : getPersonProfileUploadURL,
		getServiceURL : getServiceURL,
		getDetachManagedPersonsURL : getDetachManagedPersonsURL,
		setHomePageMode : setHomePageMode,
		getHomePageMode : getHomePageMode,
		idle             : 0,
		deletingUserMode : 1,
		deletedUserMode  : 2, 
		addingUserMode   : 3,
		addedUserMode    : 4	
	};
}
	($N));